package com.seven.webhook.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.seven.webhook.model.bean.alertBean.Rule;
import com.seven.webhook.model.bean.alertBean.RuleGroups;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@TableName("monitor_group")
@EqualsAndHashCode(callSuper = false)
public class MonitorGroup implements Serializable {
    @TableId(type = IdType.AUTO)
    private String id;
    @TableField("file_path")
    private String filePath;
    @TableField("group_name")
    private String groupName;
    @TableField(exist = false)
    private List<MonitorRule> monitorRules;


    public static List<RuleGroups> parseRuleGroupList(List<MonitorGroup> monitorGroupList) {
        ArrayList<RuleGroups> re = new ArrayList<>();
        monitorGroupList.forEach(s -> {
            RuleGroups ruleGroups = s.parseRuleGroups();
            re.add(ruleGroups);
        });
        return re;
    }

    public RuleGroups parseRuleGroups() {
        RuleGroups ruleGroup = new RuleGroups();
        ruleGroup.setName(this.groupName);
        ArrayList<Rule> rules = new ArrayList<>();
        monitorRules.forEach(s -> {
            rules.add(s.parseRule());
        });
        ruleGroup.setRules(rules);
        return ruleGroup;
    }
}
